#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

char* cmd_system(const char* command);
int main()
{
    //char str[20]={"0"};
    char* result = cmd_system("losetup -f")；
    //通过该方法可以将char*转换为char数组
    //strcpy(str,result);
    printf("The result:%s\n",result);
    return 0;
}

char* cmd_system(const char* command)
{
    char* result = "";
    FILE *fpRead;
    fpRead = popen(command, "r");
    char buf[1024];
    memset(buf,'\0',sizeof(buf));
    while(fgets(buf,1024-1,fpRead)!=NULL)
    { 
　　     result = buf;
    }
    if(fpRead!=NULL)
        pclose(fpRead);
    return result;
}